// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

// 已注册 入口
import Vue from "vue";

// import { getInfoByIdUrl } from "./Ajax/index"

import App from "./App";
import router from "./router/index";
import Mint from "mint-ui";
import store from "./store/index"; //引入状态管理 store
import common from "./common/index";
// import Utility from "./common/Utility";

// import Vconsole from 'vconsole'
// let vConsole = new Vconsole()
// Vue.use(vConsole)

import "./lib/common.css";
import "@/assets/css/iconfont/iconfont.css";
import "@/assets/css/family.css";

document.body.style.fontFamily = "mm3";

Vue.use(Mint);
// Vue.prototype.$http = axios

import lang from "./lang";
Vue.prototype.Lang = lang;

import vueg from "vueg"; //专场动画

const options = {
  duration: "0.32", //转场动画时长，默认为0.3，单位秒
  firstEntryDisable: false, //值为true时禁用首次进入应用时的渐现动画，默认为false
  firstEntryDuration: ".6", //首次进入应用时的渐现动画时长，默认为.6
  forwardAnim: "slideOutRight", //前进动画，默认为fadeInRight
  backAnim: "slideOutLeft", //后退动画，默认为fedeInLeft
  sameDepthDisable: false, //url深度相同时禁用动画，默认为false
  tabs: [
    // {
    //     name:'home'
    // },{
    //     name:'my'
    // }
  ],
  //默认为[]，name对应路由的name,以实现类似app中点击tab页面水平转场效果，如tab[1]到tab[0]，会使用backAnim动画，tab[1]到tab[2]，会使用forwardAnim动画
  tabsDisable: false, //值为true时，tabs间的转场没有动画，默认为false
  disable: false //禁用转场动画，默认为false，嵌套路由默认为true
};

Vue.use(vueg, router, options); // 传入实例化后的router, Options为可选的插件配置

// import md5 from 'js-md5';
// Vue.prototype.$md5 = md5

// 引入mockjs
// import './Ajax/mock'

// 引入fastclick  在  ios 上 会引起   mintui  滚动组件  点透
// import fastClick from 'fastclick'

//使用faseclick

// fastClick.attach(document.body)

import "mint-ui/lib/style.css";

let encrypt_PublicKey = `MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAsm9gD6L21qAJG
   WbU9ZSCdmppx96gECxKyKXluOtLhaTPf0hpJwcFd2fWJczM+YlRexYU1YVuPbq2oIQhq
   OBDdsD+y3S+kkXfObWe13mJjzoRrg3xDA5hWY9sMLwqZ7RFnNIGjz22VmI5xbEH311O
   3X4clvZz2ofGaVnYoHYQGMptRwuHvL7/MV5SVlBzxvw4XTig1muUql1321c3tLvuLHhmo+Q
   9rfUq0ef8lptxwOptvxgsAC5D71wlqOBrO4unspBZ6FNRBznB8sdSHZAWotpKCoCXztV+O
   dEH9EdlS84B+e1vJMRqCFmYjMcm5OZ7dcwKBs/LqSU4R3pq2gMxyy4Xp/+WAp9xiS7+b
   gWMnGrLeI01spXaVxYnB8Vc7D74xLPqISNYBpsAvEwA+bOKur5i4LS18A3ZBEvXXIGdz/Xk
   ylR5KGN2dTY725XRxDIBOVbyU0WJG4OsQNsMldddlwGWsopTg3R/4khNn/DrclN5GXSxl
   DVWWtgsMB3J0aneGNfPBJuVU0aoC1pDKA+YUzOlTRsgJJKAxn83+SlmAapkyw1AVqhoE
   eW6m0MosT8fVgT7b+cheupm1vZz5lRoxL/QKWVdlI8gYpzFeLLmore8pi1BUq4f1OK1feCl
   eSqxlcgPn2/XtRxtH+jl3oP8HHCRIB8VnI31McBhjSHOoiECAwEAAQ==`;
import JsEncrypt from "jsencrypt";
let rsa = new JsEncrypt();
rsa.setPublicKey(encrypt_PublicKey);
Vue.prototype.RSA = rsa;

Vue.prototype.$jsEncrypt = JsEncrypt


Vue.config.productionTip = false;
//  3秒后加载地图
new Promise((resolve, reject) => {
  setTimeout(() => {
    (function() {
      var s = document.createElement("script");
      s.type = "text/javascript";
      s.async = true;
      s.src =
        "https://maps.googleapis.com/maps/api/js?key=AIzaSyBdg2GibvPd-f7wxpEDOqmDBXWu6Zwf4B8&sensor=true";
      var x = document.getElementsByTagName("script")[0];
      x.parentNode.insertBefore(s, x);
    })();
    (function() {
      var s = document.createElement("script");
      s.type = "text/javascript";
      s.async = true;
      s.src =
        "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js";
      var x = document.getElementsByTagName("script")[0];
      x.parentNode.insertBefore(s, x);
    })();
    resolve();
  }, 3000);
}).catch(err => {
  common.toast({
    message: err,
    time: 3000
  });
});

new Promise(function(resolve, reject) {
  // console.log("Utility", Utility.getSearchString("token"));
  // 与安卓交互 将值保存到vuex 中
  let data = window.zegopay.getUserData();
  //console.log(  JSON.parse(data) )
  let activeData = JSON.parse(JSON.parse(data).activeData);

  store.state.userInfo.isCreditRecharge =
    JSON.parse(data).isCreditRecharge || "";
  store.state.userInfo.fuid = JSON.parse(data).fuid || "";
  store.state.userInfo.account = JSON.parse(data).account || "";

  store.state.userInfo.activate = activeData.status || "";
  store.state.userInfo.contrId = activeData.contrId || "";
  store.state.userInfo.fmchId = activeData.fmchId || "";
  store.state.userInfo.mchClientIp = activeData.mchClientIp || "";

  store.state.lang = JSON.parse(data).lang;

  //
}).catch(err => {
  //  //console.log(err.message)
  common.toast({
    message: err.message,
    time: 2000
  });
});

router.beforeEach((to, from, next) => {
  if (store.state.userInfo.fuid) {
    next();
  } else {
    common.toast({
      message: "fuid  miss",
      time: 2000
    });

    window.zegopay.returnMain();
  }
});

router.afterEach((to, from) => {
  // ...
});

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  store,
  components: { App },
  template: "<App/>"
});
